package org.springblade.modules.enterprise.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.enterprise.entity.EsmsProductCloud;
import org.springblade.modules.enterprise.service.IEsmsProductCloudService;
import org.springblade.modules.enterprise.vo.EsmsProductCloudVO;
import org.springblade.modules.enterprise.wrapper.EsmsProductCloudWrapper;
import org.springblade.modules.system.service.IDictService;
import org.springblade.modules.system.vo.DictVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/enterprise/product-info")
@Api(value = "产品信息", tags = "(api)产品信息")
public class ProductApi {

	private IDictService dictService;

	private IEsmsProductCloudService productService;

	/**
	 * 获取产品分类字典
	 */
	@GetMapping("release_type")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取产品分类", notes = "release_service_type")
	public R<List<DictVO>> getProductDict() {
		HashMap<String, Object> map = new HashMap<>();
		map.put("code", "release_service_type");
		return R.data(dictService.childList(map, 1423168101003845633L));
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "详情", notes = "传入esmsProductCloud")
	public R<EsmsProductCloudVO> detail(EsmsProductCloud esmsProductCloud) {
		EsmsProductCloud detail = productService.getOne(Condition.getQueryWrapper(esmsProductCloud));
		return R.data(EsmsProductCloudWrapper.build().entityVO(detail));
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入esmsProductCloud")
	public R<IPage<EsmsProductCloudVO>> list(EsmsProductCloud esmsProductCloud, Query query) {
		IPage<EsmsProductCloud> pages = productService.page(Condition.getPage(query), Condition.getQueryWrapper(esmsProductCloud));
		return R.data(EsmsProductCloudWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "分页", notes = "传入esmsProductCloud")
	public R<IPage<EsmsProductCloudVO>> page(EsmsProductCloudVO esmsProductCloud, Query query) {
		IPage<EsmsProductCloudVO> pages = productService.selectEsmsProductCloudPage(Condition.getPage(query), esmsProductCloud);
		return R.data(pages);
	}
}
